#ifndef CAR_STRUCT_HH
#define CAR_STRUCT_HH 1


#include <string>
#include <iostream>
#include <vector>
#include "otl8.hpp"

static const char*  car_struct_s = "SELECT ID, CODE, POWER, FUEL, TANK, OWNERSHIP FROM CAR_STRUCT";

static const char*  car_struct_i = "INSERT INTO CAR_STRUCT ( ID, CODE, POWER, FUEL, TANK, OWNERSHIP )VALUES(:f1<int>, :f2<char[128]>, :f3<float>, :f4<int>, :f5<int>, :f6<int>)";

static const char* car_struct_c = "CREATE TABLE CAR_STRUCT ( ID INTEGER , CODE VARCHAR(128) , POWER FLOAT , FUEL INTEGER , TANK INTEGER , OWNERSHIP INTEGER )";
class car_struct
{



public:
car_struct():_id(0), _code(""), _power(0), _fuel(0), _tank(0), _ownership(0){_select=car_struct_s;_insert=car_struct_i;_create=car_struct_c;}


car_struct(int a__id, std::string a__code, float a__power, int a__fuel, int a__tank, int a__ownership):_id(a__id) , _code(a__code) , _power(a__power) , _fuel(a__fuel) , _tank(a__tank) , _ownership(a__ownership) {_select=car_struct_s;_insert=car_struct_i;_create=car_struct_c;}


int id(){return  _id;}
void set_id(int a__id){ _id = a__id;}


std::string code(){return  _code;}
void set_code(std::string a__code){ _code = a__code;}


float power(){return  _power;}
void set_power(float a__power){ _power = a__power;}


int fuel(){return  _fuel;}
void set_fuel(int a__fuel){ _fuel = a__fuel;}


int tank(){return  _tank;}
void set_tank(int a__tank){ _tank = a__tank;}


int ownership(){return  _ownership;}
void set_ownership(int a__ownership){ _ownership = a__ownership;}


car_struct & operator=( const car_struct & x)
{
	_id =  x._id;
	_code =  x._code;
	_power =  x._power;
	_fuel =  x._fuel;
	_tank =  x._tank;
	_ownership =  x._ownership;
	return *this;
}


bool operator==( const car_struct & x)
{
	return 	_id ==  x._id &&
	_code ==  x._code &&
	_power ==  x._power &&
	_fuel ==  x._fuel &&
	_tank ==  x._tank &&
	_ownership ==  x._ownership;
}


friend std::istream& operator >> (std::istream& ist, car_struct & t)
{
	if (!(ist >> t._id)) return ist;
	if (!(ist >> t._code)) return ist;
	if (!(ist >> t._power)) return ist;
	if (!(ist >> t._fuel)) return ist;
	if (!(ist >> t._tank)) return ist;
	if (!(ist >> t._ownership)) return ist;

	return ist;
}

friend std::ostream& operator << (std::ostream& ost, car_struct & t)
{
	ost << t._id << " ";
	ost << t._code << " ";
	ost << t._power << " ";
	ost << t._fuel << " ";
	ost << t._tank << " ";
	ost << t._ownership << " ";

	return ost;
}

/*
friend otl_stream& operator >> (otl_stream& ist, car_struct & t)
{
	ist >> t._id;
	ist >> t.buf; t._code=(const char*)t.buf;
	ist >> t._power;
	ist >> t._fuel;
	ist >> t._tank;
	ist >> t._ownership;

	return ist;
}

friend otl_stream& operator << (otl_stream& ost, car_struct & t)
{
	ost << t._id ;
	ost << t._code.c_str() ;
	ost << t._power ;
	ost << t._fuel ;
	ost << t._tank ;
	ost << t._ownership ;

	return ost;
}
*/

std::string select_stmt() { return _select; }
std::string insert_stmt() { return _insert; }
std::string create_stmt() { return _create; }


private:

	int	_id;
	std::string	_code;
	float	_power;
	int	_fuel;
	int	_tank;
	int	_ownership;
	std::string _create;
	std::string _select;
	std::string _insert;
char buf[128];
};
#endif
